<template>
  <div class="agentShop_manage">
    <c-title :hide="false" :text="'推客店铺管理'"></c-title>
    <div class="bgBox"></div>
    <div class="shopBox">
      <img :src="infoData.avatar_image" class="image" alt="" />
      <div class="conten_shop">
        <div class="store_name">{{ infoData.shop_name }}</div>
        <div class="desc">{{ infoData.shop_desc }}</div>
      </div>
      <i class="iconfont icon-shezhi2" @click="toSetting" v-if="infoData.status != '-1' && infoData.status != '-2'"></i>
    </div>
    <div class="agentShop_Box" v-if="infoData">
      <template v-if="infoData.status == 0">
        <div class="tips">请购买指定商品缴纳保证金</div>
        <div class="tips" style="margin-top:0;color: #B8B8B8;font-size: 0.81rem;">(缴纳保证金需要单独购买商品)</div>
        <div class="listBox">
          <div class="lis" v-for="(item, index) in goodsList" :key="index" @click="toGood(item)">
            <div class="lisimg">
              <img :src="item.thumb" alt="" />
            </div>
            <div class="conten_bottom">
              <div class="title">{{ item.title }}</div>
              <div class="priceTxt">￥{{ item.price }}</div>
            </div>
          </div>
        </div>
      </template>
      <template v-else>
        <div class="lineBox">
          <div class="line">
            <i class="iconfont icon-baodan"></i>
            <div class="txt">
              已缴纳保证金<sapn style="color: #F15353;">¥{{ infoData.price }}</sapn
              >，店铺正常营业
            </div>
            <div class="btn" @click="refundApply">{{ infoData.status == "-1" ? "申请中" : "申请退款" }}</div>
          </div>
          <div class="line">
            <i class="iconfont icon-life-code"></i>
            <div class="txt">店铺推广二维码</div>
            <div class="btn" @click="getPoster">店铺推广</div>
          </div>
        </div>
      </template>
    </div>
    <yz_goodsPoster v-model="posterShow" :defaultImg="defaultImg"></yz_goodsPoster>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
import yz_goodsPoster from "components/ui_components/yz_goodsPoster";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      infoData: {
        status: "0"
      },
      goodsList: [],
      posterShow: false,
      defaultImg: "",

      isLoadMore: true,
      page: 1,
      total_page: 0
    };
  },
  activated() {
    this.page = 1;
    this.isLoadMore = true;
    this.total_page = 0;
    this.getData();
  },
  methods: {
    async refundApply() {
      if (this.infoData.status != -1) {
        this.$dialog
          .confirm({ message: `是否确认退款，退款成功后店铺将会被关闭?` })
          .then(async () => {
            let { data, msg, result } = await $http.post("plugin.agent-shop.frontend.apply.refundApply", {}, "");
            this.$toast(msg);
            this.getData();
          })
          .catch(() => {});
      }
    },
    toGood(item) {
      this.$router.push(this.fun.getUrl("goods", { id: item.id }, {}));
    },
    toSetting() {
      this.$router.push(this.fun.getUrl("agentShop_setting", {}, {}));
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.agent-shop.frontend.agent.manage", {}, "");
      if (!result) return this.$toast(msg);
      this.infoData = data;
      if (data.status == 0) {
        this.getGood();
      }
    },
    async getGood() {
      let { data, msg, result } = await $http.post("plugin.agent-shop.frontend.goods.searchGoods", {}, "");
      if (!result) return this.$toast(msg);
      this.goodsList = data.data;
      this.total_page = data.last_page;
      if (!this.total_page) {
        this.total_page = 0;
      }
      this.isLoadMore = true;
    },
    async getPoster() {
      let { data, msg, result } = await $http.post("plugin.agent-shop.frontend.agent.getPoster", { id: this.infoData.id }, "");
      if (!result) return this.$toast(msg);
      this.defaultImg = data.url;
      this.posterShow = true;
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page
        };
        let { data, msg, result } = await $http.post("plugin.agent-shop.frontend.goods.searchGoods", json, "");
        this.isLoadMore = true;
        if (!result) {
          this.$toast(msg);
          this.page = this.page - 1;
          this.isLoadMore = false;
        } else {
          this.goodsList = this.goodsList.concat(data.data);
        }
      }
    }
  },
  components: { yz_goodsPoster }
};
</script>
<style lang="scss" scoped>
.agentShop_manage {
  .bgBox {
    width: 23.44rem;
    height: 4.63rem;
    background: linear-gradient(180deg, #f15353 0%, rgba(241, 83, 83, 0) 100%);
    border-radius: 0rem 0rem 0rem 0rem;
  }

  .agentShop_Box {
    padding: 0 0.75rem;
    box-sizing: border-box;
    padding-bottom: 2rem;
    .lineBox {
      padding: 0 0.75rem;
      border-radius: 0.56rem;
      background: #ffffff;
      margin-top: 0.63rem;

      .line {
        display: flex;
        align-items: center;
        padding: 0.8rem 0;
        border-bottom: 0.03rem solid #f0f0f1;
        .icon-life-code {
          font-weight: bold;
          font-size: 1rem;
        }
        .txt {
          font-size: 0.81rem;
          color: #00001c;
          flex: 1;
          text-align: left;
          margin-left: 0.38rem;
        }
        .icon-baodan {
          flex-shrink: 0;
        }
        .btn {
          flex-shrink: 0;
          margin-left: 0.34rem;
          font-size: 0.81rem;
          color: #f15353;
          padding: 0.47rem 0.56rem;
          box-sizing: border-box;
          line-height: 1rem;
          border: 0.03rem solid #f15353;
          border-radius: 0.88rem;
        }
      }
    }

    .tips {
      font-weight: bold;
      font-size: 0.94rem;
      color: #00001c;
      margin-top: 0.94rem;
      text-align: left;
    }
    .listBox {
      display: flex;
      flex-wrap: wrap;
      margin-top: 0.88rem;
      justify-content: space-between;
      .lis {
        display: flex;
        flex-direction: column;
        background: #ffffff;
        padding-bottom: 0.8rem;
        border-radius: 0.75rem;
        margin-bottom: 0.5rem;
        width: 10.66rem;
        overflow: hidden;
        .lisimg {
          width: 100%;
          height: 10.66rem;
          border-radius: 0.75rem;
          img {
            width: 100%;
            height: 100%;
            border-radius: 0.75rem;
          }
        }
      }
      .conten_bottom {
        padding: 0 0.75rem;
        overflow: hidden;
        .title {
          font-weight: bold;
          font-size: 0.81rem;
          line-height: 1rem;
          color: #00001c;
          text-align: left;
          margin-top: 0.5rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .priceTxt {
          font-weight: 500;
          font-size: 1rem;
          line-height: 1.1rem;
          color: #f15353;
          text-align: left;
          margin-top: 0.5rem;
        }
      }
    }
  }
  .shopBox {
    margin: 0 0.75rem;
    margin-top: -2.88rem;
    height: 4.63rem;
    background: #ffffff;
    border-radius: 0.56rem 0.56rem 0.56rem 0.56rem;
    display: flex;
    justify-content: space-between;
    padding: 0.78rem 0.66rem;
    .icon-shezhi2 {
      margin-right: 0.12rem;
    }
    .image {
      width: 3rem;
      height: 3rem;
      background: #f5f5f5;
      border-radius: 50%;
      margin: 0;
    }
    .conten_shop {
      flex: 1;
      margin-left: 0.5rem;
      text-align: left;
      display: flex;
      flex-direction: column;
      justify-content: center;
      .store_name {
        font-weight: bold;
        font-size: 1rem;
        line-height: 1.1rem;
        margin-bottom: 0.4rem;
      }
    }
  }
}
</style>
